package Test;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class TestJson2 {
    public static void main(String[] args) {
//        将json字符串转成java对象

        Gson gson = new GsonBuilder().create();
        String json = "{\"name\":\"yang\",\"age\":18,\"courses\":[\"java\",\"python\"]}";

        Student student = new Gson().fromJson(json, Student.class);

        Student student1 = gson.fromJson(json, Student.class);

        System.out.printf("name:%s, age:%d, courses:%s%n",student.getName(),student.getAge(),student.getCourses());

        System.out.printf("name:%s, age:%d, courses:%s%n",student1.getName(),student1.getAge(),student1.getCourses());



    }
}
